package ru.ifmo.rybakov.muclumon.analysis;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import ru.ifmo.rybakov.muclumon.Task;

public class TaskCluster implements ICluster {
	private final List<Task> tasks = new ArrayList<Task>();
	
	public TaskCluster(Task task) {
		tasks.add(task);
	}
	
	public TaskCluster(Collection<Task> tasks) {
		this.tasks.addAll(tasks);
	}
	
	public Collection<Task> getTasks() {
		return Collections.unmodifiableCollection(tasks);
	}
	
	public Collection<?> getObjects() {
		return getTasks();
	}
	
	/* (non-Javadoc)
	 * @see ru.ifmo.rybakov.muclumon.analysis.IClusterManager#merge(ru.ifmo.rybakov.muclumon.analysis.ICluster, ru.ifmo.rybakov.muclumon.analysis.ICluster)
	 */
	@Override
	public ICluster merge(ICluster other) {
		assert (other instanceof TaskCluster) : "Invalid cluster type";
		TaskCluster otherTaskCluster = (TaskCluster) other;
		List<Task> tasks = new ArrayList<Task>();
		tasks.addAll(this.tasks);
		tasks.addAll(otherTaskCluster.getTasks());
		return new TaskCluster(tasks);
	}
}
